<?php 

	require_once '../function.php';

	$category = xiu_fetch_db_all('select * from categories;');
	$posts = xiu_fetch_db_all("select 
		posts.id,
		posts.title,
		posts.created,
		posts.html,
		posts.content,
		posts.views,
		posts.likes,
		posts.feature,
		posts.user_id,
		users.nickname,
		categories.name as category_name
		from posts
		inner join categories on posts.category_id = categories.id
		inner join users on posts.user_id = users.id
		where posts.status = 2
		order by posts.created desc
		limit 0,10;
		");
	// if (isset($_SESSION['index_user'])) {
	// 	$user = $_SESSION['index_user'];
	// }

 ?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>首页</title>
	<link rel="stylesheet" type="text/css" href="/static/vendors/bootstrap4.6/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="/index/index.css">
</head>
<body>
	<div class="main">
		<?php include './inc/head-bar.php' ?>
		<div class="container-fluid">
			<div class="row">
				<div class="col-md-2">
					<ul class="asid-category">
						<li class="category-hd">
							<h5>文章分类</h5>
						</li>
						<?php foreach ($category as $item): ?>
							<li><a href="javascript:;"><?php echo $item['name'] ?><span><?php echo xiu_fetch_db_one('select count(1) as num from posts where category_id ='.$item['id'])['num'] ?>篇</span></a></li>
						<?php endforeach ?>
					</ul>
				</div>
				<div class="col-md-9">
					<?php foreach ($posts as $item): ?>
						<div class="row community-post" >
							<div class="post-info col-md-8">
								<a href="/index/post.php?id=<?php echo $item['id']; ?>">
									<p class="head-info"><?php echo $item['title'] ?></p>
									<p class="content-info"><?php echo $item['html']; ?></p>
								</a>
								<span class="iconfont">&#xe663;</span>&nbsp;
								<?php echo $item['views']; ?>&nbsp;&nbsp;&nbsp;
								<span class="iconfont">&#xe62c;</span>&nbsp;
								<?php echo $item['likes']; ?>&nbsp;&nbsp;&nbsp;&nbsp;
								<?php echo $item['created']; ?>&nbsp;&nbsp;&nbsp;&nbsp;
								<span>类别：</span><?php echo $item['category_name']; ?>&nbsp;&nbsp;&nbsp;&nbsp;
								<span>作者：<a href="/index/person.php?id=<?php echo $item['user_id'] ?>"><?php echo $item['nickname'] ?></a></span>
							</div>
							<div class="right col-md-4">
								<img src="<?php echo $item['feature']; ?>" width="100px">
							</div>
						</div>
					<?php endforeach ?>
				</div>
			</div>
		</div>
	</div>

	<script src="/static/vendors/jQuery.js"></script>
	<script src="/static/vendors/bootstrap4.6/js/bootstrap.bundle.js"></script>
</body>
</html>